package com.quanyan.runningriding.web.running.Admin;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.validation.base.Update;
import com.quanyan.runningriding.entity.db.TbRunMusicType;
import com.quanyan.runningriding.entity.vo.run.MusicVo;
import com.quanyan.runningriding.entity.vo.run.req.RunMusicFMVo;
import com.quanyan.runningriding.entity.vo.run.resp.MusicFMVo;
import com.quanyan.runningriding.service.RunMusicFMService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * Created by liubin on 2016/11/23.
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class MusicFMController {
    @Autowired
    private RunMusicFMService runMusicFMService;
    private Logger logger = LoggerFactory.getLogger(VideoAdminController.class);



    @RequestMapping(value = "/musicFMList", method = RequestMethod.POST)
    public APIResponse<PageObj<List<TbRunMusicType>>> musicFMList(@RequestBody Map<String, Object> paramMap) {
        Byte type = MapUtils.getByte(paramMap, "type");
        String typeName = MapUtils.getString(paramMap,"typeName");
        String describeDetail = MapUtils.getString(paramMap,"describeDetail");
        Integer pageNum = MapUtils.getInteger(paramMap,"pageNum");
        Integer pageSize = MapUtils.getInteger(paramMap,"pageSize");
        PageObj<List<TbRunMusicType>> result = runMusicFMService.musicFMList(type, typeName,describeDetail,pageNum,pageSize);
        return APIResponse.returnSuccess(result);
    }

    @RequestMapping(value = "/updateMusicFM", method = RequestMethod.POST)
    public APIResponse<?> updateMusicFM(@RequestBody @Validated(Update.class) MusicFMVo musicFMVo) {
        APIResponse<?> result = runMusicFMService.updateMusicFM(musicFMVo);
        return result;
    }

    @RequestMapping(value = "/deleteMusicFM", method = RequestMethod.POST)
    public APIResponse<?> deleteMusicFM(@RequestBody Map<String, Object> paramMap) {
        Integer MusicId = MapUtils.getInteger(paramMap,"musicId");
        APIResponse<?> result = runMusicFMService.deleteMusicFM(MusicId);
        return result;
    }

    @RequestMapping(value = "/insertMusicFM",method = RequestMethod.POST)
    public APIResponse<?> insertMusicFM(RunMusicFMVo runMusicFMVo){
        APIResponse<?> result = runMusicFMService.insertMusicFM(runMusicFMVo);
        return result;
    }
}
